home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / commio0b.zip / ASYNC.PAS < prev    next >
Pascal/Delphi Source File  |  1996-05-14  |  61KB  |  1,304 lines

  1. {
  2.    You should'nt have to include this unit in your program's uses statement.
  3.    This is all low level stuff, and should only be accessed through the
  4.    COMMIO unit.
  5.    You might also notice that this ASYNC.PAS is almost the same as the one
  6.    found in the DDPLUS door library.  I changed a couple of things, and added
  7.    [very] limited FIFO support.  Only the recieve FIFOs are turned on.
  8. }
  9. {*--------------------------------------------------------------------------*}
  10. {*                                                                          *}
  11. {*  Status byte definition (C_Status):                                      *}
  12. {*                                                                          *}
  13. {*  7   6   5   4   3   2   1   0                                           *}
  14. {*  |   |   |   |   |   |   |   |____ Input buffer empty                    *}
  15. {*  |   |   |   |   |   |   |________ Input buffer full                     *}
  16. {*  |   |   |   |   |   |____________ Output buffer empty                   *}
  17. {*  |   |   |   |   |________________ Output buffer full                    *}
  18. {*  |   |   |   |____________________ Input buffer overflow                 *}
  19. {*  |   |   |________________________ Output buffer overflow                *}
  20. {*  |   |____________________________ Hard handshake active (xmit stopped)  *}
  21. {*  |________________________________ Soft handshake active (xmit stopped)  *}
  22. {*                                                                          *}
  23. {*  Control byte definition (C_Ctrl):                                       *}
  24. {*                                                                          *}
  25. {*  7   6   5   4   3   2   1   0                                           *}
  26. {*  |   |   |   |   |   |   |   |____ Enable RTS handshake                  *}
  27. {*  |   |   |   |   |   |   |________ Enable CTS handshake                  *}
  28. {*  |   |   |   |   |   |____________ Enable software handshake             *}
  29. {*  |   |   |   |   |________________                                       *}
  30. {*  |   |   |   |____________________                                       *}
  31. {*  |   |   |________________________                                       *}
  32. {*  |   |____________________________                                       *}
  33. {*  |________________________________                                       *}
  34. {*                                                                          *}
  35. {****************************************************************************}
  36.  
  37. {$R-,V-,B-,S-}
  38.  
  39. Unit ASYNC;
  40.  
  41. INTERFACE
  42.  
  43. {----------------------------------------------------------------------------}
  44.  
  45. Const
  46.   C_MinBaud = 300;
  47.   C_MaxBaud = 115200;
  48.   C_MaxPort = 4;
  49.   C_MaxCom : byte = C_MaxPort;
  50.   C_PortAddr : Array[1..C_MaxPort] Of Word = ($03F8,$02F8,$03E8,$02E8);
  51.   C_PortInt  : Array[1..C_MaxPort] Of Byte = (4,3,4,3);
  52.  
  53. {----------------------------------------------------------------------------}
  54.  
  55. Type
  56.   C_VectorArray  = Array[0..15] Of Pointer;
  57.   C_PointerArray = Array[1..C_MaxPort] Of Pointer;
  58.   C_WordArray    = Array[1..C_MaxPort] Of Word;
  59.   C_ByteArray    = Array[1..C_MaxPort] Of Byte;
  60.   C_CharArray    = Array[1..C_MaxPort] Of Char;
  61.   C_BooleanArray = Array[1..C_MaxPort] Of Boolean;
  62.  
  63. {----------------------------------------------------------------------------}
  64.  
  65. Var
  66.   { Base port addresses & interrupt usage }
  67. {  C_PortAddr : Array[1..C_MaxPort] Of Word;
  68.   C_PortInt  : Array[1..C_MaxPort] Of Byte;{}
  69.   ComPort  : Byte;
  70.   C_InBufPtr,C_OutBufPtr : C_PointerArray;    { Input/output buffer pointers }
  71.   C_InHead,C_OutHead     : C_WordArray;       { Input/output head pointers }
  72.   C_InTail,C_OutTail     : C_WordArray;       { Input/output tail pointers }
  73.   C_InSize,C_OutSize     : C_WordArray;       { Input/output buffer sizes }
  74.   C_RTSOn,C_RTSOff       : C_WordArray;       { RTS assert/drop buffer points }
  75.   C_StartChar,C_StopChar : C_CharArray;       { Soft hndshake start/stop char }
  76.   C_Status,C_Ctrl        : C_ByteArray;       { STATUS and CONTROL registers }
  77.   C_XL3Ptr               : C_ByteArray;
  78.   C_PortOpen             : C_BooleanArray;    { Port open/close flags }
  79.   C_Temp                 : Word;              { Used for debugging }
  80.   C_msrport              : word;
  81. { RTSOn,RTSOff           : Word;             { RTS assert/drop buffer points }
  82. {  oldier,oldmcr          : byte;}
  83.   c_oldier,c_oldmcr      : c_bytearray;
  84.   c_oldfcr               : c_bytearray;      { old FIFO status -jason}
  85.   c_fifoOK               : c_booleanarray;
  86.   c_buffull              : c_wordarray;
  87. {  C_Cascade              : Byte;              { Flag set 0 normally }
  88. {  C_CascadeOK            : boolean;           { Flag if IRQ > 7 }
  89.   C_Cascade              : c_Bytearray;        { Flag set 0 normally }
  90.   C_CascadeOK            : c_booleanarray;     { Flag if IRQ > 7 }
  91.  
  92. {----------------------------------------------------------------------------}
  93.  
  94. Function  ComReadCh(ComPort:Byte) : Char;
  95. Function  ComReadChW(ComPort:Byte) : Char;
  96. { Procedure ComWriteCh(ComPort:Byte; Ch:Char); }
  97. Procedure ComWriteChW(ComPort:Byte; Ch:Char);
  98. Procedure SetDTR(ComPort:Byte; Assert:Boolean);
  99. Procedure SetRTS(ComPort:Byte; Assert:Boolean);
  100. {
  101. Procedure SetOUT1(ComPort:Byte; Assert:Boolean);
  102. Procedure SetOUT2(ComPort:Byte; Assert:Boolean);
  103. }
  104. Function  CTSStat(ComPort:Byte) : Boolean;
  105. Function  RTSStat(ComPort:Byte) : Boolean;
  106. Function  DSRStat(ComPort:Byte) : Boolean;
  107. Function  RIStat(ComPort:Byte) : Boolean;
  108. Function  DCDStat(ComPort:Byte) : Boolean;
  109. Procedure SetRTSMode(ComPort:Byte; Mode:Boolean; RTSOn,RTSOff:Word);
  110. Procedure SetCTSMode(ComPort:Byte; Mode:Boolean);
  111. Procedure SoftHandshake(ComPort:Byte; Mode:Boolean; Start,Stop:Char);
  112. Procedure ClearCom(ComPort:Byte; IO:Char);
  113. Function  ComBufferLeft(ComPort:Byte; IO:Char) : Word;
  114. Procedure ComWaitForClear(ComPort:Byte);
  115. Procedure I_ComWrite(ComPort:Byte; St:String);
  116. Procedure I_ComWriteln(ComPort:Byte; St:String);
  117. Procedure I_ComWriteWithDelay(ComPort:Byte; St:String; Dly:Word);
  118. Procedure I_ComReadln(ComPort:Byte; Var St:String; Size:Byte; Echo:Boolean);
  119. Function  ComExist(ComPort:Byte) : Boolean;
  120. Function  ComTrueBaud(Baud:Longint) : Real;
  121. Procedure ComParams(ComPort:Byte; Baud:LongInt; WordSize:Byte; Parity:Char; StopBits:Byte);
  122. Function  OpenCom(ComPort:Byte; InBufferSize,OutBufferSize:Word) : Boolean;
  123. Procedure CloseCom(ComPort:Byte);
  124. Procedure CloseAllComs;
  125.  
  126. {----------------------------------------------------------------------------}
  127.  
  128. IMPLEMENTATION
  129.  
  130. Uses DOS,CRT;
  131.  
  132. {$L ASYNC.OBJ}
  133.  
  134. Const
  135.   C_IER = 1;                           { 8250 register offsets }
  136.   C_IIR = 2;
  137.   C_LCR = 3;
  138.   C_MCR = 4;
  139.   C_LSR = 5;
  140.   C_MSR = 6;
  141.   C_SCR = 7;
  142.  
  143. Var
  144.   C_OldINTVec : C_VectorArray;        { Storage for old hardware INT vectors }
  145.   X : Byte;                            { Used by initialization code }
  146.  
  147. {****************************************************************************}
  148. {*                                                                          *}
  149. {*  Procedure INT_Handler; External;                                        *}
  150. {*                                                                          *}
  151. {*  Hardware interrupts 0-15 (vectors $08 - $0F,$70 - $77) are pointed to   *}
  152. {*  this routine.  It is for internal use only and should NOT be called     *}
  153. {*  directly.  Written in assembly language (see SLASYNC.ASM).              *}
  154. {*                                                                          *}
  155. {****************************************************************************}
  156.  
  157. Procedure INT_Handler; External;
  158.  
  159. {****************************************************************************}
  160. {*                                                                          *}
  161. {*  Procedure ComReadCh(ComPort:Byte) : Char; External;                     *}
  162. {*                                                                          *}
  163. {*  ComPort:Byte  ->  Port # to use (1 - C_MaxCom)                          *}
  164. {*